package LC;

/**
 * @ClassName MatchCore
 * @Description: TODO
 * @Author hl
 * @Date 2020/8/3
 * @Version V1.0
 **/
public class MatchCore {
    public boolean match(char[] str, char[] pattern)
    {
        if(str==null||pattern==null){
            return  false;
        }
        return  matchCore(str,0,pattern,0);

    }
    public boolean matchCore(char[]str,int strIndex,char[] pattern,int patternIndex){
        if(str.length==strIndex&&pattern.length==patternIndex){
            return  true;
        }
        if(str.length!=strIndex&&pattern.length==patternIndex){
            return  false;
        }
        if(patternIndex+1<pattern.length&&pattern[patternIndex+1]=='*'){//第二个字符是*
            if((strIndex!=str.length&&str[strIndex]==pattern[patternIndex])||
                    (strIndex!=str.length&&pattern[patternIndex]=='.')){//第一个字符相匹配
                return matchCore(str,strIndex+1,pattern,patternIndex+2)||
                        matchCore(str,strIndex,pattern,patternIndex+2)||
                        matchCore(str,strIndex+1,pattern,patternIndex);

            }else{
                return  matchCore(str,strIndex,pattern,patternIndex+2);
            }

        }
        if((strIndex!=str.length&&pattern[patternIndex]==str[strIndex])||
                (strIndex!=str.length&&pattern[patternIndex]=='.')){
            return matchCore(str,strIndex+1,pattern,patternIndex+1);
        }
    return  false;
    }

}
